//
//  SKTabbar.swift
//  swiftwb
//
//  Created by jiasongkai on 15/7/6.
//  Copyright © 2015年 jiasongkai. All rights reserved.
//

import UIKit

class SKTabbar: UITabBar {


    override func layoutSubviews() {
        super.layoutSubviews()
    
        let tabCount : CGFloat = 5
        let width = self.bounds.size.width / tabCount
        let height = self.bounds.size.height
        let frame = CGRectMake(0, 0, width, height);
        
        var index = 0
        for view in subviews as [UIView]{
            if view is UIControl && !(view is UIButton){
                
                if index == 2{
                    self.addBtn?.frame = CGRectOffset(frame, CGFloat(index) * width, 0)
                    ++index
                }
                view.frame = CGRectOffset(frame, CGFloat(index) * width, 0)
//                print("\(view.frame), \()")
                ++index
            }
        }

        
    }
    
    
    
    lazy var addBtn : UIButton? = {
        
        let button = UIButton();
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState:.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState:.Selected)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Selected)
        button .addTarget(self, action: "pop", forControlEvents: .TouchUpInside)
        self.addSubview(button);
        return button;
        
    }()
    
    func pop() {
        let vc = UIViewController()
        vc.view.backgroundColor = UIColor.redColor()
        print(vc)
    }

}
